import CommonConfig from '@config/Common';
import FoodConfig from '@config/Food';

// 食物类
class Food {
    element: HTMLElement;       // 食物的元素

    constructor() {
        this.element = document.querySelector('#food')!;
        this.change();
    }

    get X() {
        return this.element.offsetLeft;
    }

    get Y() {
        return this.element.offsetTop;
    }

    change() {
        //将游戏平台划分成几部分
        const part = (CommonConfig.stageWidth - FoodConfig.width)/CommonConfig.baseMove;

        const left = Math.round(Math.random() * part) * CommonConfig.baseMove;
        const top = Math.round(Math.random() * part) * CommonConfig.baseMove;

        this.element.style.left = left + 'px';
        this.element.style.top = top + 'px';
    }
}

export default Food;